Git Product home page Git Product logo

Comments (10)

SergeyKanzhelev avatar SergeyKanzhelev commented on May 16, 2024

I wonder if it's because of Wordpress's wp_remote_post here. Nothing else should cause process creation. Is there any information from them was it because of this call? I'll also dig around

from applicationinsights-wordpress.

gpeipman avatar gpeipman commented on May 16, 2024

Support was support and seemed to me that guy was far from bits and bytes. So, there's no information that can help us. I asked him for technical guys but wellโ€ฆ Still, maybe I have something for you.

I went through PHP configuration and I saw it is running in CGI mode. It should mean that every request gets its own PHP process. I think this is why they have page where suggested number of requests per hosting package are listed.

As my blog uses caching then requests to posts and other pages are usually fast - 0.2-0.5s and perhaps this is why it is able to survive more load than I have ever expected. Although cache is used it is served by WordPress plugin and it means that ApplicationInsights works also for cached requests (I suppose).

There's one option to make the number of requests to pile and this can happen with server-side requests to other sites when network connection is slow or when server on the other end doesn't respond fast enough. I mean, if request to external machine takes usually let's say one second then it's suddenly 8 seconds and requests start piling as they are waiting for response.

If this is the case then I can think about few ways how to solve the problem:

  1. Add request timeout as configuration option so users with busy sites can set it to some small value. If timeout comes then your plugin just fails clean. This way PHP processes cannot pile up so easily and go through the limits of smaller hosting packages.

  2. Send information to Application Insights service using JavaScript. Just prepare request data and let browser do the job. I'm not very much sure about this option as server-side page loading time is not so accurate anymore. But then there's no network dependencies on your plugin level.

  3. Mix of two above. If request to Application Insights times out then let's automatically switch to JavaScript option.

Not sure if point 2 is valid and has any meaning but it looks like a good idea to break one dependency to external resource.

from applicationinsights-wordpress.

SergeyKanzhelev avatar SergeyKanzhelev commented on May 16, 2024

@gpeipman I think this may be the case I don't think sending to Application Insights will take seconds, but sometimes it may be up to a second (with slower networks).

One solution may be to send request and do not wait for response. But wp_remote_post doesn't seem to allow for this. Alternative is to curl in separate process, but it wouldn't address your problem.

Another issue suggest to implement some batching and back off logic: microsoft/ApplicationInsights-PHP#50

So perhaps one good solution will be to start background process that uploads data and all requests just dump information to specific file location.

Does HostGator allow some writeable file system location and start separate processes?

from applicationinsights-wordpress.

gpeipman avatar gpeipman commented on May 16, 2024

Yes, of course, otherwise it would be close to impossible to use WordPress normally.

My simple shared hosting package supports also cron jobs, so I think it has everything needed.

If it is okay for Application Insights then it's not a problem when cron job runs once or twice per hour.

from applicationinsights-wordpress.

SergeyKanzhelev avatar SergeyKanzhelev commented on May 16, 2024

@gpeipman I was thinking more like once a minute. Otherwise the delay for data upload will be too high. So maybe php script with the infinite loop and sleep. Not sure if it's a best practice in PHP.

Would you be interested to contribute? These SDKs (PHP and wordpress) are community supported, not officially maintained. But I'll be happy to review and help where I can.

from applicationinsights-wordpress.

gpeipman avatar gpeipman commented on May 16, 2024

Hosting guys usually doesn't like those endless scripts and some of them may have also guarding systems that kill processes that have been up for too long. To get rid of this there are two options:

  • cron job with one minute interval
  • upload script called from some external process using wget, curl etc

If cron job happens frequently it's possible that hosting takes it as a sign of something suspicious. In this means it would be important even there to have small request timeouts.

To contribute I have to understand first how the code works. I know PHP language and some internals of WordPress but I haven't written anything serious on PHP more than ten years. But let's try.

from applicationinsights-wordpress.

SergeyKanzhelev avatar SergeyKanzhelev commented on May 16, 2024

Contributing instructions are straightforward: https://github.com/Microsoft/ApplicationInsights-WordPress/blob/master/CONTRIBUTING.md You can use docker or just host a local version of wordpress.

This line constructs the client:
https://github.com/Microsoft/ApplicationInsights-WordPress/blob/7b782fd771d7df70874aaad6cba0d50f3d8409a2/src/Server_Instrumentation.php#L23

Constructor of TelemetryClient accepts channel as an argument: https://github.com/Microsoft/ApplicationInsights-PHP/blob/fd82b5e1c3b2002b63ac85fad69b3aae2c4c3620/ApplicationInsights/Telemetry_Client.php#L26-L30 So you can create a custom copy of channel in this repository that will implement the same methods as this channel: https://github.com/Microsoft/ApplicationInsights-PHP/blob/fd82b5e1c3b2002b63ac85fad69b3aae2c4c3620/ApplicationInsights/Channel/Telemetry_Channel.php#L221-L230

And method send will do some advanced logic. If long running scripts is bad - maybe store some last running time in server variables or in file system. And run script only when difference in time is more than couple minutes. So send will save data to file system, check the time difference and if much time passed - run a script to read data from file storage and send them to Application Insights.

from applicationinsights-wordpress.

SergeyKanzhelev avatar SergeyKanzhelev commented on May 16, 2024

How this note can help you get started. Let me know if you need more help. And don't hesitate to point on unclear contributing docs or code structure. We want to make contributions easy and straightforward

from applicationinsights-wordpress.

rkmaier avatar rkmaier commented on May 16, 2024

@SergeyKanzhelev I am php dev and would like take care of this issue.

from applicationinsights-wordpress.

gpeipman avatar gpeipman commented on May 16, 2024

I got something done and it even works. Request parameters needed by trackRequest() method are saved to file and there's cron job that goes through all saved files, sends data to Application Insights and deletes files. As I'm not WordPress expert I don't have much idea how to fit it to this plugin the way that others can also use it.

Anyway, if somebody needs urgent solution then feel free to ping me while I try to figure out how to make this functionality as integral part of plugin.

from applicationinsights-wordpress.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.