[Apple notifies APNs] I wonder if PushSharp has been used by many people ?, Apnspushsharp

Source: Internet
Author: User

[Apple notifies APNs] I wonder if PushSharp has been used by many people ?, Apnspushsharp

I haven't written anything for a long time. I have recently studied Jenkins. If you are interested, you can come and have a chat. It is very important to learn DevOps.

Recently, I am in charge of a project that requires the notification of APNs. It is quite difficult to develop this independently, so we use the third-party open-source PushSharp. There are many notifications, such as Amazon, GSM, BlackBerry, Windows, and apple.

First, let me talk about the problems encountered during use. When intensive requests are sent to the APNs server after the connection, there are usually two situations: InvalidToken and ConnectionError, however, there is a small potential rule in it, that is, continuous feedback on InvalidToken, whether you are the correct Token in the future, it will reject your connection and directly feedback ConnectionError, which I often encounter, after checking du Niang, someone said that Apple's APNs was used to prevent malicious attacks. Think about what APNs can endure if people generate a random invalid Token to request you in large numbers, it must be rejected consecutively. Of course, it will certainly be able to be sent again after a while, because it will not ban IP addresses.

If no notification is sent successfully, you can filter out ConnectionError and send the notification again. Also, if you think its sending request is too slow, you can adjust the number of internal connection object pools. The Code is as follows:

Var config = ApnsConfigurationFactory. createConfiguration (); var apnsBroker = new ApnsServiceBroker (config); apnsBroker. changeScale (10); // number of internal connection object pools. We recommend that you use up to 10. Generally, a quad-core server can be controlled at a maximum of 40% apnsBroker. start ();

If the machine is strong enough, you can open more points, 20, 30, 50 can all be, the more open, he can process large concurrent request notifications faster.

By the way, after deploying the production environment of PushSharp, I found that sending requests in large concurrency will cause service downtime and found two major problems:

I. The Buffer part of the Console. WriteLine method will cause memory overflow. Therefore, I have confined this Code. The Code is adjusted as follows:

        static Log()        {            counters = new Dictionary<CounterToken, Stopwatch>();            loggers = new List<ILogger>();#if DEBUG            AddLogger(new ConsoleLogger());#endif        }

The above is the static constructor in the PushSharp. Core. Log class adjusted the code, and I will not allow the execution of Console. WriteLine

2. The problem is caused by the internal failure of the thread security queue. I will replace it with the thread security queue, as shown in the figure below:

Location: PushSharp. Apple. ApnsConnection

 

After the above changes, the system is still running well and has not experienced any downtime. We also hope to give you a warning.

If you need the changed DLL, contact me.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.